package com.ujcms.cms.core.domain;

import com.ujcms.cms.core.domain.base.ActionBase;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.springframework.lang.Nullable;

import java.io.Serial;
import java.io.Serializable;
import java.time.OffsetDateTime;

/**
 * 动作 实体类
 *
 * @author PONY
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class Action extends ActionBase implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 数据库表名
     */
    public static final String TABLE_NAME = "action";

    /**
     * 动作ID
     */
    @NotNull
    @Schema(description = "动作ID")
    private Long id = 0L;

    /**
     * 站点ID
     */
    @NotNull
    @Schema(description = "站点ID")
    private Long siteId = 0L;

    /**
     * 用户ID
     */
    @Nullable
    @Schema(description = "用户ID")
    private Long userId;

    /**
     * IP
     */
    @Length(max = 45)
    @Nullable
    @Schema(description = "IP")
    private String ip;

    /**
     * Cookie
     */
    @Nullable
    @Schema(description = "Cookie")
    private Long cookie;

    /**
     * 动作对象类型
     */
    @Length(max = 50)
    @NotNull
    @Schema(description = "动作对象类型")
    private String refType = "";

    /**
     * 动作对象ID
     */
    @NotNull
    @Schema(description = "动作对象ID")
    private Long refId = 0L;

    /**
     * 动作选项
     */
    @Length(max = 255)
    @NotNull
    @Schema(description = "动作选项")
    private String refOption = "";

    /**
     * 创建日期
     */
    @NotNull
    @Schema(description = "创建日期")
    private OffsetDateTime created = OffsetDateTime.now();

    @Nullable
    public Long getUserId() {
        return userId;
    }

    public void setUserId(@Nullable Long userId) {
        this.userId = userId;
    }

    @Nullable
    public String getIp() {
        return ip;
    }

    public void setIp(@Nullable String ip) {
        this.ip = ip;
    }

    @Nullable
    public Long getCookie() {
        return cookie;
    }

    public void setCookie(@Nullable Long cookie) {
        this.cookie = cookie;
    }

    public Action() {
    }

    public Action(String refType, Long refId, String refOption,
                  Long siteId, @Nullable Long userId, String ip, Long cookie) {
        this.refType = refType;
        this.refId = refId;
        this.refOption = refOption;

        this.siteId = siteId;
        this.userId = userId;
        this.ip = ip;
        this.cookie = cookie;
    }
}